﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KProject.Controller;
using KProject.Model;

namespace KProject
{
    public partial class FormConcurso : Form
    {
        private ConcursoController cc;
        bool editing;

        public FormConcurso(ConcursoController cc, bool editing)
        {
            this.cc = cc;
            this.editing = editing;

            InitializeComponent();

            if (editing)
            {
                this.Text = "Editar";
                bOkNovo.Text = "Salvar";
                tbNomeConcurso.Text = cc.Concurso.Nome;
                dpDataConcurso.Value = cc.Concurso.Data;
                tbCidadeConcurso.Text = cc.Concurso.Cidade;
            }
        }

        private void bCancelarNovo_Click(object sender, EventArgs e)
        {
            if (!editing)
                cc.Concurso = new Concurso();
            this.Close();
        }

        private void bOkNovo_Click(object sender, EventArgs e)
        {
            try
            {
                cc.Salvar(tbNomeConcurso, dpDataConcurso, tbCidadeConcurso);
            }
            catch (VerifyingException ex)
            {
                MessageBox.Show(ex.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                this.Close();
            }
        }
    }
}
